使用Restlet和GAE过滤根路径
我有一段代码,当访问ROOT_URI
时,我需要能够触发MyFilter:
private static final String ROOT_URI = "/";
private static final String ROOT_REST_URI = "/rest/";
@Override
public Restlet createInboundRoot() {
Guice.createInjector(new GuiceConfigModule(this.getContext()),
new SelfInjectingServerResourceModule());
Router router = new Router(getContext());
router.attach(ROOT_URI + "{id}", new GaeRedirector(getContext(), "{id}"));
router.attach(ROOT_REST_URI, GaeRootServerResource.class);
MyFilter mFilter = new MyFilter(getContext());
MyFilter.setNext(router);
return mFilter;
}
MyFilter仅在访问ROOT\u REST\u URI时触发。Restlet团队已经通过邮件组建议,我需要首先将路由放入根URI中
问题是,
ROOT_URI
不在路由中,因为它在web中。xml,一个welcome-file
设置指向索引。html。因此,当访问http://localhost:8080/
时,它返回索引。html页面李>
我还尝试添加(作为根URI的路由,以使MyFilter在根URI上工作):
Directory directory = new Directory(getContext(), "war:///doc");
router.attach(ROOT_URI, directory);
然而,这个目录路由不适用于GAE。它似乎根本不会触发。使用此目录代码访问http://localhost:8080/
,仍然是索引。显示html,不触发MyFilter
现在,如果我删除web中的<welcome-file>
。xml。MyFilter被触发,但现在无法显示index.html
。除非通过向请求中添加/index.html
来明确说明
对于这种情况有什么解决方案强>
# 1 楼答案
我将尝试为目录设置默认索引名,如下所示: